package com.example.demo.web.vo.response;

import com.fasterxml.jackson.annotation.JsonInclude;

/**
 * @author ayatsuji
 * @date 2022-04-10 21:25
 * @since
 */
public class Result<T> {
    private final Integer code;
    private final String errorMsg;
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private final T data;

    private Result(Integer code, String errorMsg, T data) {
        this.code = code;
        this.errorMsg = errorMsg;
        this.data = data;
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(200, "", data);
    }

    public static <T> Result<T> success() {
        return success(null);
    }

    public static <T> Result<T> failure(Integer code, String errorMsg) {
        return new Result<>(code, errorMsg, null);
    }

    public Integer getCode() {
        return code;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public T getData() {
        return data;
    }
}
